package it.univpm.diiga.semanticsearch.ricerca;
import it.univpm.diiga.semanticsearch.configurazione.Configuration;
import it.univpm.diiga.semanticsearch.servizi.Link;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;


public abstract class Ricerca {
	
   private String keyword;
   private int level;
   
   
   
   private Hashtable<String, Object> configuration = new Hashtable<String, Object>();
   
   
   
   public Ricerca(){
	   try {
		Configuration.findLocalConfiguration();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	   
	   try{
		   Configuration.findLocalConfiguration();
	   }catch(Exception e){
		   e.printStackTrace();
	   }
   }
 
   public abstract List<Link> execSearch(String keyword ) throws Exception;
   

   
   public String getKeyword(){
	   return this.keyword;
   }
   
   public List<URL> getDefaultRepo(){
	   //return this.defaultRepoLink;
	   return Configuration.getDefaultRepoLink();
   }
   
   public File getLocalRepo(){
	   //return this.defaultRepoLink;
	   if (!Configuration.getLocalRepoLink().equals(""))
		   return (File)Configuration.getLocalRepoLink();
	   return null;
   }
   
   public List<URL> getPublicRepo(){
	   //return this.publicRepoLink;
	   return Configuration.getPublicRepoLink();
   }
   
   public int getLevel(){
	   return this.level;
	   
   }
   
   public Hashtable getSettings(){
	   return this.configuration;
   }
   

   
   
   /*
    * ECCEZIONI
    */
  
   
   public class RemoteExc extends FileConfigExc {

		public RemoteExc() {
	// Il costruttore di Exception chiamato inizializza la
	// variabile privata message
	    }
	    public String toString() {
	        return getMessage();
	    }
	}
   
   
   public class FileConfigExc extends Exception {
	    public FileConfigExc() {
	// Il costruttore di Exception chiamato inizializza la
	// variabile privata message
	        super("Impossibile trovare il repository di default");
	    }
	    public String toString() {
	        return getMessage();
	    }
	}
   public class LocalExc extends FileConfigExc {
	    public LocalExc() {
	// Il costruttore di Exception chiamato inizializza la
	// variabile privata message
	    }
	    public String toString() {
	        return getMessage();
	    }
	}
   

}
